home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / ue312src.zip / FMR.C < prev    next >
C/C++ Source or Header  |  1993-01-06  |  15KB  |  661 lines

  1. /*    FMR.C:    Fujitsu FMR series Driver
  2.  *        for MicroEMACS 3.12
  3.  *        (C)Copyright 1993 by Daniel M. Lawrence
  4.  *
  5.  *    Note that this driver relies on GDS.SYS being loaded!
  6.  */
  7.  
  8. #define    termdef    1            /* don't define term external */
  9.  
  10. #include        <stdio.h>
  11. #include    "estruct.h"
  12. #include    "eproto.h"
  13. #include        "edef.h"
  14. #include    "elang.h"
  15.  
  16. #if     FMR
  17.  
  18. /*    FMR special key definitions    */
  19.  
  20. typedef struct KEYDEF {
  21.     unsigned int kf_JIScode;    /* JIS code of key */
  22.     int kf_len;            /* length of key sequence */
  23.     char *kf_def;            /* keystroke sequence */
  24. } KEYDEF;
  25.  
  26. KEYDEF functab[] = {
  27.  
  28.     /* F1 - F10 */
  29.     0x8001, 0, NULL,
  30.     0x8002, 0, NULL,
  31.     0x8003, 0, NULL,
  32.     0x8004, 0, NULL,
  33.     0x8005, 0, NULL,
  34.     0x8006, 0, NULL,
  35.     0x8007, 0, NULL,
  36.     0x8008, 0, NULL,
  37.     0x8009, 0, NULL,
  38.     0x800a, 0, NULL,
  39.  
  40.     /* S-F1 - S-F10 */
  41.     0x800b, 0, NULL,
  42.     0x801d, 0, NULL,
  43.     0x8021, 0, NULL,
  44.     0x8022, 0, NULL,
  45.     0x8023, 0, NULL,
  46.     0x8024, 0, NULL,
  47.     0x8025, 0, NULL,
  48.     0x8026, 0, NULL,
  49.     0x8027, 0, NULL,
  50.     0x8028, 0, NULL,
  51.  
  52.     /* other special keys */
  53.  
  54.     /* cursor arrows */
  55.     0x1e, 0, NULL,
  56.     0x1f, 0, NULL,
  57.     0x1d, 0, NULL,
  58.     0x1c, 0, NULL
  59.  
  60. };
  61.  
  62. #define    NUMFKEYS    sizeof(functab)/sizeof(KEYDEF)
  63.  
  64. /*    EMACS internal key sequences mapped from FMR keys    */
  65.  
  66. KEYDEF newtab[NUMFKEYS] = {
  67.  
  68.     /* F1 - F10 */
  69.     0x8001, 3, "\000\0101",
  70.     0x8002, 3, "\000\0102",
  71.     0x8003, 3, "\000\0103",
  72.     0x8004, 3, "\000\0104",
  73.     0x8005, 3, "\000\0105",
  74.     0x8006, 3, "\000\0106",
  75.     0x8007, 3, "\000\0107",
  76.     0x8008, 3, "\000\0108",
  77.     0x8009, 3, "\000\0109",
  78.     0x800a, 3, "\000\0100",
  79.  
  80.     /* S-F1 - S-F10 */
  81.     0x800b, 3, "\000\0501",
  82.     0x801d, 3, "\000\0502",
  83.     0x8021, 3, "\000\0503",
  84.     0x8022, 3, "\000\0504",
  85.     0x8023, 3, "\000\0505",
  86.     0x8024, 3, "\000\0506",
  87.     0x8025, 3, "\000\0507",
  88.     0x8026, 3, "\000\0508",
  89.     0x8027, 3, "\000\0509",
  90.     0x8028, 3, "\000\0500",
  91.  
  92.     /* other special keys */
  93.  
  94.     /* cursor arrows */
  95.     0x1e, 3, "\000\010P",
  96.     0x1f, 3, "\000\010N",
  97.     0x1d, 3, "\000\010B",
  98.     0x1c, 3, "\000\010F"
  99. };
  100.  
  101. union REGS rg;        /* cpu register for use of DOS calls */
  102. struct SREGS sg;    /* cpu segment registers         */
  103.  
  104. #if    PROTO
  105. int PASCAL NEAR fnclabel(int f, int n);
  106. int PASCAL NEAR readparam( int *v);
  107. void PASCAL NEAR dobbnmouse(void);
  108. void PASCAL NEAR docsi( int oh);
  109. void PASCAL NEAR ttputs(char *string);
  110. void PASCAL NEAR charwrite(int row, char *outstr, int forg, int left, int right);
  111. #else
  112. int PASCAL NEAR fnclabel();
  113. int PASCAL NEAR readparam();
  114. void PASCAL NEAR dobbnmouse();
  115. void PASCAL NEAR docsi();
  116. void PASCAL NEAR ttputs();
  117. void PASCAL NEAR charwrite();
  118. #endif
  119.  
  120. #define NROW    24                      /* Screen size.                 */
  121. #define NCOL    80                      /* Edit if you want to.         */
  122. #define    NPAUSE    100            /* # times thru update to pause */
  123. #define    MARGIN    8            /* size of minimim margin and    */
  124. #define    SCRSIZ    64            /* scroll size for extended lines */
  125. #define BEL     0x07                    /* BEL character.               */
  126. #define ESC     0x1B                    /* ESC character.               */
  127.  
  128. /* Forward references.          */
  129. extern int PASCAL NEAR fmrmove();
  130. extern int PASCAL NEAR fmreeol();
  131. extern int PASCAL NEAR fmreeop();
  132. extern int PASCAL NEAR fmrbeep();
  133. extern int PASCAL NEAR fmropen();
  134. extern int PASCAL NEAR fmrrev();
  135. extern int PASCAL NEAR fmrclose();
  136. extern int PASCAL NEAR fmrkopen();
  137. extern int PASCAL NEAR fmrkclose();
  138. extern int PASCAL NEAR fmrcres();
  139. extern int PASCAL NEAR fmrparm();
  140.  
  141. unsigned int octype;        /* original cursor type */
  142. unsigned int ocraster;        /* original cursor raster line limits */
  143.  
  144. #if    COLOR
  145. extern int PASCAL NEAR fmrfcol();
  146. extern int PASCAL NEAR fmrbcol();
  147.  
  148. static int cfcolor = -1;    /* current forground color */
  149. static int cbcolor = -1;    /* current background color */
  150.  
  151. int bcmap[16] =            /* background color map */
  152.     {0, 4, 8, 12, 2, 6, 10, 14,
  153.      1, 5, 9, 13, 3, 7, 11, 15};
  154. #endif
  155.  
  156. /*
  157.  * Standard terminal interface dispatch table. Most of the fields point into
  158.  * "termio" code.
  159.  */
  160. NOSHARE TERM term    = {
  161.     NROW-1,
  162.         NROW-1,
  163.         NCOL,
  164.         NCOL,
  165.     0, 0,
  166.     MARGIN,
  167.     SCRSIZ,
  168.     NPAUSE,
  169.         fmropen,
  170.         fmrclose,
  171.     fmrkopen,
  172.     fmrkclose,
  173.         ttgetc,
  174.         ttputc,
  175.         ttflush,
  176.         fmrmove,
  177.         fmreeol,
  178.         fmreeop,
  179.         fmreeop,
  180.         fmrbeep,
  181.     fmrrev,
  182.     fmrcres
  183. #if    COLOR
  184.     , fmrfcol,
  185.     fmrbcol
  186. #endif
  187. };
  188.  
  189. #if    COLOR
  190. PASCAL NEAR fmrfcol(color)        /* set the current output color */
  191.  
  192. int color;    /* color to set */
  193.  
  194. {
  195.     if (color == cfcolor)
  196.         return;
  197.     ttputc(ESC);
  198.     ttputc('[');
  199.     fmrparm((color & 7)+30);
  200.     ttputc('m');
  201.     cfcolor = color;
  202. }
  203.  
  204. PASCAL NEAR fmrbcol(color)        /* set the current background color */
  205.  
  206. int color;    /* color to set */
  207.  
  208. {
  209.     if (color == cbcolor)
  210.         return;
  211. #if    0
  212.     ttputc(ESC);
  213.     ttputc('[');
  214.     fmrparm(color+40);
  215.     ttputc('m');
  216. #endif
  217.         cbcolor = color;
  218. }
  219. #endif
  220.  
  221. PASCAL NEAR fmrmove(row, col)
  222. {
  223.         ttputc(ESC);
  224.         ttputc('[');
  225.         fmrparm(row+1);
  226.         ttputc(';');
  227.         fmrparm(col+1);
  228.         ttputc('H');
  229. }
  230.  
  231. PASCAL NEAR fmreeol()
  232. {
  233.         ttputc(ESC);
  234.         ttputc('[');
  235.         ttputc('K');
  236. }
  237.  
  238. PASCAL NEAR fmreeop()
  239. {
  240. #if    COLOR
  241.     fmrfcol(gfcolor);
  242.     fmrbcol(gbcolor);
  243. #endif
  244.         ttputc(ESC);
  245.         ttputc('[');
  246.     ttputc('2');
  247.         ttputc('J');
  248.  
  249.     gds_erase();    /* dump the background colors */
  250. }
  251.  
  252. PASCAL NEAR fmrrev(state)        /* change reverse video state */
  253.  
  254. int state;    /* TRUE = reverse, FALSE = normal */
  255.  
  256. {
  257.     ttputc(ESC);
  258.     ttputc('[');
  259.     ttputc(state ? '7': '0');
  260.     ttputc('m');
  261.     if (state)
  262.         fmrfcol(7);
  263. }
  264.  
  265. PASCAL NEAR fmrcres()    /* change screen resolution */
  266.  
  267. {
  268.     return(TRUE);
  269. }
  270.  
  271. PASCAL NEAR spal(char *dummy)        /* change pallette settings */
  272.  
  273. {
  274.     /* none for now */
  275. }
  276.  
  277. PASCAL NEAR fmrbeep()
  278. {
  279.         ttputc(BEL);
  280.         ttflush();
  281. }
  282.  
  283. PASCAL NEAR fmrparm(n)
  284. register int    n;
  285. {
  286.         register int q,r;
  287.  
  288.         q = n/10;
  289.         if (q != 0) {
  290.         r = q/10;
  291.         if (r != 0) {
  292.             ttputc((r%10)+'0');
  293.         }
  294.         ttputc((q%10) + '0');
  295.         }
  296.         ttputc((n%10) + '0');
  297. }
  298.  
  299. PASCAL NEAR fmropen()
  300.  
  301. {
  302.     strcpy(sres, "NORMAL");
  303.     revexist = TRUE;
  304.         ttopen();
  305.  
  306.     ttputc(ESC);        /* no attributes set */
  307.     ttputc('[');
  308.     fmrparm(40);
  309.     ttputc('m');
  310.  
  311.     gds_init();        /* initialize the GDS driver */
  312. }
  313.  
  314. PASCAL NEAR fmrclose()
  315.  
  316. {
  317. #if    COLOR
  318.     fmrfcol(7);
  319.     fmrbcol(0);
  320. #endif
  321.     gds_erase();        /* close the GDS driver, clear background */
  322.     ttclose();
  323. }
  324.  
  325. PASCAL NEAR fmrkopen()    /* open the keyboard */
  326.  
  327. {
  328.     /* save the original function key definitions */
  329.     savekeys(&functab);
  330.     setkeys(&newtab);
  331.  
  332.     /* save the cursor type */
  333.     rg.h.ah = 0x0a;        /* read cursor form */
  334.     int86(0x91, &rg, &rg);
  335.     octype = rg.h.al;    /* save old cursor type */
  336.     ocraster = rg.x.dx;    /* save old cursor rasters */
  337.  
  338.     /* and set it as a block */
  339.     rg.h.ah = 0x09;        /* set cursor form */
  340.     rg.h.al = 0xd1;        /* full-size, fast blink,
  341.                    high intensity, box */
  342.     int86(0x91, &rg, &rg);
  343.  
  344.     /* make sure the windows are re-framed */
  345.     upwind();
  346. }
  347.  
  348. PASCAL NEAR fmrkclose()    /* close the keyboard (a noop here) */
  349.  
  350. {
  351.     setkeys(&functab);
  352.     gds_erase();        /* close the GDS driver, clear bhackground */
  353.  
  354.     /* retore the original cursor */
  355.     rg.h.ah = 0x09;        /* set cursor form */
  356.     rg.h.al = octype;    /* restore original cursor type */
  357.     rg.x.dx = ocraster;    /* and raster limits */
  358.     int86(0x91, &rg, &rg);
  359. }
  360.  
  361. savekeys(ftable)    /* save function key definitions */
  362.  
  363. KEYDEF *ftable;        /* table to save definitions to */
  364.  
  365. {
  366.     char *sp;    /* ptr to new keystroke definition */
  367.     int index;    /* index into table to save */
  368.     int jindex;    /* an index into the keystroke buffer */
  369.     int len;    /* length of the keystroke buffer */
  370.     char *kptr;    /* ptr into kbuf */
  371.     char kbuf[16];    /* buffer to hold definition */
  372.  
  373.     /* set up the pointers to the temp keystroke buffer */
  374.     kptr = kbuf;
  375.     sg.ds = FP_SEG(kptr);
  376.     rg.x.di = FP_OFF(kptr);
  377.     kptr[0] = 15; /* set length of buffer */
  378.  
  379.     /* for each key to save */
  380.     for (index = 0; index < NUMFKEYS; index++) {
  381.  
  382.         /* set parameters to reading key assignment call */
  383.         rg.h.ah = 0x0f;                /* subfunction code */
  384.         rg.x.dx = ftable[index].kf_JIScode;    /* set key */
  385.  
  386.         /* call the BIOS for the info */
  387.         int86x(0x90, &rg, &rg, &sg);
  388.  
  389.         /* and record the length */
  390.         len = rg.x.cx;
  391.         ftable[index].kf_len = len;
  392.  
  393.         /* and the keystrokes */
  394.         sp = malloc(len);
  395.         if (sp == NULL)
  396.             return;
  397.         for (jindex = 0; jindex < len; jindex++)
  398.             sp[jindex] = kptr[jindex + 1];
  399.         ftable[index].kf_def = sp;
  400.     }
  401. }
  402.  
  403. setkeys(ftable)    /* set the function key definitions */
  404.  
  405. KEYDEF *ftable;        /* table to set definitions from */
  406.  
  407. {
  408.     char *sp;    /* ptr to new keystroke definition */
  409.     int index;    /* index into table to save */
  410.     int jindex;    /* an index into the keystroke buffer */
  411.     int len;    /* length of the keystroke buffer */
  412.     char *kptr;    /* ptr into kbuf */
  413.     char kbuf[16];    /* buffer to hold definition */
  414.  
  415.     kptr = kbuf;
  416.  
  417.     /* for each key to set */
  418.     for (index = 0; index < NUMFKEYS; index++) {
  419.  
  420.         /* set up the pointers to the temp keystroke buffer */
  421.         sg.ds = FP_SEG(kptr);
  422.         rg.x.di = FP_OFF(kptr);
  423.  
  424.         /* set parameters to reading key assignment call */
  425.         rg.h.ah = 0x0e;                /* subfunction code */
  426.         rg.h.al = 1;                /* add 0 to the key address */
  427.         rg.x.dx = ftable[index].kf_JIScode;    /* set key */
  428.         rg.x.cx = len = ftable[index].kf_len;
  429.  
  430.         /* copy the keystrokes in */
  431.         sp = ftable[index].kf_def;
  432.         for (jindex = 0; jindex < len; jindex++) {
  433.             kptr[jindex] = sp[jindex];
  434.         }
  435.  
  436.         /* call the BIOS for the info */
  437.         int86x(0x90, &rg, &rg, &sg);
  438.     }
  439. }
  440.  
  441. /* charwrite:    write some chars directly out to the video */
  442.  
  443. void PASCAL NEAR charwrite(row, outstr, forg, left, right)
  444.  
  445. int row;    /* row of screen to place outstr on */
  446. char *outstr;    /* string to write out (must be term.t_ncol long) */
  447. int forg;    /* forground color of string to write */
  448. int left, right;    /* limits of the reverse field area */
  449.  
  450. {
  451.     /* move to the begining of the destination line */
  452.     fmrmove(row, left);
  453.     outstr += left;
  454.  
  455.     /* set the proper forground color */
  456.     fmrfcol(forg);
  457.  
  458.     /* write the text to the screen */
  459.     rg.h.ah = 0x1e;            /* Character string output */
  460.     rg.x.cx = right - left + 1;    /* # of chars to display */
  461.     sg.ds = FP_SEG(outstr);        /* point to string to display */
  462.     rg.x.di = FP_OFF(outstr);
  463.     int86x(0x91, &rg, &rg, &sg);    /* call bios to write */
  464. }
  465.  
  466. /* scwrite:    write a line directly out to the video */
  467.  
  468. PASCAL NEAR scwrite(row, outstr, forg, bacg, left, right)
  469.  
  470. int row;    /* row of screen to place outstr on */
  471. char *outstr;    /* string to write out (must be term.t_ncol long) */
  472. int forg;    /* forground color of string to write */
  473. int bacg;    /* background color */
  474. int left, right;    /* limits of the reverse field area */
  475.  
  476. {
  477.     /* separate and write this line out */
  478.     if (right == 0) {
  479.         charwrite(row, outstr, forg, 0, 79);
  480.         gds_bline(row, bacg, 0, 79);
  481.     } else {
  482.         /* left of highleghted region */
  483.         if (left > 0) {
  484.             charwrite(row, outstr, forg, 0, left - 1);
  485.             gds_bline(row, bacg, 0, left - 1);
  486.         }
  487.  
  488.         /* highlighted region */
  489.         charwrite(row, outstr, bacg, left, right);
  490.         gds_bline(row, forg, left, right);
  491.  
  492.         /* right of highlighted region */
  493.         if (right < term.t_ncol) {
  494.             charwrite(row, outstr, forg, right + 1, term.t_ncol);
  495.             gds_bline(row, bacg, right + 1, term.t_ncol);
  496.         }
  497.     }
  498.  
  499.     /* scwrite moves the cursor.... */
  500.     ttrow++;
  501.     ttcol = 0;
  502. }
  503.  
  504. #if    FLABEL
  505. int PASCAL NEAR fnclabel(f, n)        /* label a function key */
  506.  
  507. int f,n;    /* default flag, numeric argument [unused] */
  508.  
  509. {
  510.     /* on machines with no function keys...don't bother */
  511.     return(TRUE);
  512. }
  513. #endif
  514.  
  515. /****    FMR  GDS functions        ****/
  516.  
  517. /*    Some globals    */
  518.  
  519. unsigned char param[32];    /* parameter block for GDS_outdata */
  520.  
  521. /* draw operations code definitions */
  522.  
  523. #define    OP(class, elem, parlen)    class * 0x1000 + elem * 0x20 + parlen
  524. #define setpar(n, val)    param[n] = (val) & 255; param[n+1] = ((val) >> 8) & 255
  525.  
  526. gds_init()
  527.  
  528. {
  529.     /* set input parameters */
  530.     rg.h.ah = 0x80;        /* Graphics initialization function code */
  531.  
  532.     /* call GDS */
  533.     int86x(0x92, &rg, &rg, &sg);
  534.  
  535.     /* return success if AH == 0 */
  536.     if (rg.h.ah != 0)
  537.         return(FALSE);
  538.  
  539.     gds_paintmode(1);
  540.     return(TRUE);
  541. }
  542.  
  543. gds_erase()
  544.  
  545. {
  546.     /* set input parameters */
  547.     rg.h.ah = 0x84;        /* Graphics initialization function code */
  548.  
  549.     /* call GDS */
  550.     int86x(0x92, &rg, &rg, &sg);
  551.  
  552.     /* return success if AH == 0 */
  553.     return(rg.h.ah == 0);
  554. }
  555.  
  556. gds_outdata(data)    /* execute graphic data commands */
  557.  
  558. unsigned char *data;    /* graphic command buffer */
  559.  
  560. {
  561.     /* set input parameters */
  562.     rg.h.ah = 0x8f;        /* Output of graphic data function code */
  563.  
  564.     sg.ds = FP_SEG(data);    /* set address of command buffer */
  565.     rg.x.di = FP_OFF(data);
  566.  
  567.     /* call GDS */
  568.     int86x(0x92, &rg, &rg, &sg);
  569.  
  570.     /* return success if AH == 0 */
  571.     return(rg.h.ah == 0);
  572. }
  573.  
  574. gds_paintmode(mode)    /* set paint mode */
  575.  
  576. int mode;    /* forground mode for painting */
  577.  
  578. {
  579.     /* set command buffer length */
  580.     setpar(0, 4);
  581.  
  582.     /* set the graphic function code */
  583.     setpar(2, OP(5, 22, 2));
  584.  
  585.     /* set the mode */
  586.     setpar(4, mode);
  587.  
  588.     /* send it out */
  589.     return(gds_outdata(param));
  590. }
  591.  
  592. gds_boxcolor(color)    /* set box color */
  593.  
  594. int color;
  595.  
  596. {
  597.     /* set command buffer length */
  598.     setpar(0, 4);
  599.  
  600.     /* set the graphic function code */
  601.     setpar(2, OP(5, 23, 2));
  602.  
  603.     /* set the colorion */
  604.     setpar(4, color);
  605.  
  606.     /* send it out */
  607.     gds_outdata(param);
  608.  
  609.     /* set command buffer length */
  610.     setpar(0, 4);
  611.  
  612.     /* set the graphic function code */
  613.     setpar(2, OP(5, 28, 2));
  614.  
  615.     /* set the colorion */
  616.     setpar(4, color);
  617.  
  618.     /* send it out */
  619.     return(gds_outdata(param));
  620. }
  621.  
  622. /* draw a line's background color box */
  623.  
  624. gds_bline(line, color, left, right)
  625.  
  626. int line;    /* screen line to reset color on */
  627. int color;    /* color to draw background line in */
  628. int left, right; /* left and write boundry conditions on line */
  629.  
  630. {
  631.     int typos;    /* top (upper left) coord of rectangle */
  632.  
  633.     /* set the right position */
  634.     typos = line * 30;
  635.  
  636.     /* set the proper color for the line */
  637.     gds_boxcolor(bcmap[color]);
  638.  
  639.     /* set command buffer length */
  640.     setpar(0, 10);
  641.  
  642.     /* set the graphic function code */
  643.     setpar(2, OP(4, 11, 8));
  644.  
  645.     /* set the upper left point */
  646.     setpar(4, left * 14);
  647.     setpar(6, typos);
  648.  
  649.     /* set the lower right point */
  650.     setpar(8, (right + 1) * 14);
  651.     setpar(10, typos + 30);
  652.  
  653.     /* send it out */
  654.     return(gds_outdata(param));
  655. }
  656. #else
  657. fmrhello()
  658. {
  659. }
  660. #endif
  661.